package com.ys.controller.api.business;

import com.ys.entity.business.TpAmazonShopExchangeRate;
import com.ys.service.business.TpAmazonShopExchangeRateService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping("/api/inter/tpAmazonShopExchangeRate")
public class ApiInterTpAmazonShopExchangeRateController {
    private static final Logger logger = LoggerFactory.getLogger(ApiInterTpAmazonShopExchangeRateController.class);

    @Autowired
    private CommonApiService<TpAmazonShopExchangeRate> commonApiService;

    @Autowired
    private TpAmazonShopExchangeRateService tpAmazonShopExchangeRateService;

    @RequiresPermissions("tpAmazonShopExchangeRate:view")
    @RequestMapping("/search")
    @ResponseBody
    public LayuiTableVoJA search(@ModelAttribute TpAmazonShopExchangeRate cond){

        cond.setOrderby("A.createTime DESC");
        return commonApiService.searchLay(cond);
    }



    /**
     * 新增
     */
    @RequestMapping("/toAdd")
    @ResponseBody
    public R toAdd(HttpServletRequest request, @RequestParam Map<String, Object> params
    		) {
        try {
            logger.info("币种管理新增传参：" + params);
            //修改
            return tpAmazonShopExchangeRateService.add(params);
        } catch (Exception e) {
            logger.error("币种管理新增出错：", e.getMessage(), e);
            return R.error("系统正在开小差，请联系客服，我们将第一时间为您解决！");
        }
    }

    /**
     * 修改
     */
    @RequestMapping("/toEdit")
    @ResponseBody
    public R toEdit(HttpServletRequest request, @RequestParam Map<String, Object> params
    ) {
        try {
            logger.info("币种管理修改传参：" + params);
            //修改
            return tpAmazonShopExchangeRateService.edit(params);
        } catch (Exception e) {
            logger.error("币种管理修改出错：", e.getMessage(), e);
            return R.error("系统正在开小差，请联系客服，我们将第一时间为您解决！");
        }
    }

    @RequestMapping("/searchTk")
    @ResponseBody
    public LayuiTableVoJA searchTk(@ModelAttribute TpAmazonShopExchangeRate cond){
        cond.setStatus(1);
        cond.setOrderby("A.createTime ASC");
        return commonApiService.searchLay(cond);
    }

    @RequestMapping("/searchForModal")
    @ResponseBody
    public LayuiTableVoJA searchForModal(@ModelAttribute TpAmazonShopExchangeRate cond){
        cond.setStatus(1);
        cond.setOrderby("A.Id ASC");
        return commonApiService.searchLay(cond);
    }

}
